<template>
  <div>
    <van-cell-group>
      <van-field v-model="user.phone" label="手机号" placeholder="请输入手机号" />
    </van-cell-group>
    <van-cell-group>
      <van-field v-model="user.password" label="密码" type="password" placeholder="请输入密码" />
    </van-cell-group>
    <div class="btn">
    <van-button type="primary" @click="login">登录</van-button>
    <van-button type="primary" @click="$router.push('/register')">注册</van-button>
    </div>
    
  </div>
</template>

<script>
import { reqLogin } from "../../http/http"
import { Toast } from 'vant';
export default {
  // 账号admin,密码;123 登录成功
  data() {
    return {
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      reqLogin(this.user).then((res) => {
        if (res.data.code == 200) {
          Toast.success(res.data.msg);
          // alert(res.data.msg);
          localStorage.setItem("isLogin", 1);
          localStorage.setItem("userInfo", JSON.stringify(res.data.list));
          this.$router.push("/index/home");
        }
      });
    },
  },
};
</script>

<style scoped>
  .btn{
    text-align: center;
  }
  .btn button{
    margin-right: 0.15rem;
  }
</style>